<?php
function strtohex($src) {
	$str = '';
	$strlen = strlen($src);

	for($i = 0; $i < $strlen; $i++) {
		#ord得到字符串单个字符的ASCII值，dechex转为16进制
		$str .="0x".str_pad(dechex(ord(substr($src, $i, 1))), 2, '0', STR_PAD_LEFT);
		#$str .=str_pad(dechex(ord(substr($src, $i, 1))), 2, '0', STR_PAD_LEFT);
	}
	return $str;
}

function hextostr($src) {
	$str = '';
	$strlen = strlen($src);

	for($i = 0; $i < $strlen;$i += 4) {
		#hexdec将密文以4为单位，转为10进制，取出ASCII，hexdec将ASCII转为字符 
		$str .= chr(hexdec(substr($src,$i,4)));
	}
	return $str;
}

function hexIntToStr($int) {
	$str = '';
	$strlen = strlen($int);

	for($i = 0; $i < $strlen;$i += 2) {
		$str .="0x" . substr($int, $i, 2);
	}

	return $str;
}

function makekey(/*$p, */$i) {
	$p = '0000000000000000000';
	$p = substr($p, -8);
	$i = substr($i, -9);

	$p = str_pad(decbin($p), 26, "0", STR_PAD_LEFT);
	$i = str_pad(decbin($i), 30, "0", STR_PAD_LEFT);
	return $p . $i;
}


echo "<br>";
echo "<br>";
echo "<br>";
echo strtohex('abcdefg');
echo "<br>";
echo hextostr('0x610x620x630x640x650x660x67');
echo "<br>";
echo "<br>";
for($i=0;$i<10;$i++){
	 echo "(10^".$i.")=".(10^$i);
	 echo "<br>";
}
echo "<br>";
echo "<br>";
echo "0x".str_pad(dechex(ord(null)), 2, '0', STR_PAD_LEFT); 